package com.algorithms;

import com.algorithms.graphs.Graph;
import com.algorithms.utils.AlgorithmException;

public class test_graphs extends Thread {
	public void run(){
		search();
		
		//min_spanning_search();
	}
	
	private void min_spanning_search(){
		Graph graph = new Graph();
		graph.addVertex('A'); 	// 0
		graph.addVertex('B'); 	// 1
		graph.addVertex('C'); 	// 2
		graph.addVertex('D'); 	// 3
		graph.addVertex('E');	// 4
		
		graph.addEdge(0, 1);	// AB
		graph.addEdge(1, 2); 	// BC
		graph.addEdge(0, 3); 	// AD
		graph.addEdge(1, 3); 	// AD
		graph.addEdge(3, 4);	// DE
		graph.addEdge(1, 4);	// BE
		
		System.out.print("Visits: ");
		try{	
			graph.mst(); 
		}catch(AlgorithmException alEx){
			System.err.println(alEx.getMessage());
		}
		System.out.println();
	}

	
	private void search(){
		Graph graph = new Graph();
		graph.addVertex('A'); 	// 0
		graph.addVertex('B'); 	// 1
		graph.addVertex('C'); 	// 2
		graph.addVertex('D'); 	// 3
		graph.addVertex('E');	// 4
		
		graph.addEdge(0, 1);	// AB
		graph.addEdge(1, 2); 	// BC
		graph.addEdge(0, 3); 	// AD
		graph.addEdge(1, 3); 	// AD
		graph.addEdge(3, 4);	// DE
		graph.addEdge(1, 4);	// BE
		
		System.out.print("Visits: ");
		try{	
			graph.dfs(); 
		}catch(AlgorithmException alEx){
			System.err.println(alEx.getMessage());
		}
		System.out.println();
		
		try{	
			graph.bfs(); 
		}catch(AlgorithmException alEx){
			System.err.println(alEx.getMessage());
		}
		System.out.println();
	}
	
	public static void main(String args[]){
		new test_graphs().start();
	}
}
